]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
appDisplay: Make page panning smoother on touch
authorJasper St. Pierre <jstpierre@mecheye.net>
Sun, 27 Apr 2014 15:18:04 +0000 (11:18 -0400)
committerJasper St. Pierre <jstpierre@mecheye.net>
Mon, 28 Apr 2014 17:30:09 +0000 (13:30 -0400)
Currently, our logic for page panning isn't great. If the user starts a
pan upwards and hesitates over a new page, we'll go to the *next* page
on release, since the difference is greater, but the velocity wound down
to 0.

Instead of trying to treat it like page down or scrolls, simply do the
math to find the page where the user scrolled to.

This is unfortunately broken for fast swipes, since the user doesn't get
far enough into the new page to make a difference. I'm getting the
impression we'll need a gesture recognizer for this, though, however
crude. Simple hacks I tried, like a velocity multiplier, didn't work
properly.

https://bugzilla.gnome.org/show_bug.cgi?id=729064

js/ui/appDisplay.js
js/ui/iconGrid.js

index 0f5baf82c65d47d58a37d09514344f6642a64122..e04c59ac1a746c68d016a0f47746dd2b60f21a37 100644 (file)
@@ -41,9 +41,7 @@ const MIN_FREQUENT_APPS_COUNT = 3;
 const INDICATORS_BASE_TIME = 0.25;
 const INDICATORS_ANIMATION_DELAY = 0.125;
 const INDICATORS_ANIMATION_MAX_TIME = 0.75;
-// Fraction of page height the finger or mouse must reach
-// to change page
-const PAGE_SWITCH_TRESHOLD = 0.2;
+
 const PAGE_SWITCH_TIME = 0.3;
 
 const VIEWS_SWITCH_TIME = 0.4;
@@ -528,15 +526,19 @@ const AllView = new Lang.Class({
     _onPanEnd: function(action) {
          if (this._displayingPopup)
             return;
-        let diffCurrentPage = this._diffToPage(this._currentPage);
-        if (diffCurrentPage > this._scrollView.height * PAGE_SWITCH_TRESHOLD) {
-            if (action.get_velocity(0)[2] > 0)
-                this.goToPage(this._currentPage - 1);
-            else
-                this.goToPage(this._currentPage + 1);
-        } else {
-            this.goToPage(this._currentPage);
-        }
+
+        let pageHeight = this._grid.getPageHeight();
+
+        // Calculate the scroll value we'd be at, which is our current
+        // scroll plus any velocity the user had when they released
+        // their finger.
+
+        let velocity = -action.get_velocity(0)[2];
+        let endPanValue = this._adjustment.value + velocity;
+
+        let closestPage = Math.round(endPanValue / pageHeight);
+        this.goToPage(closestPage);
+
         this._panning = false;
     },
 
index 6bbbcb7a8284ab1bb65fd1f54e97ea65cac62999..16c58e92f9c88e7b183ea4f73f84e80582d1a30c 100644 (file)
@@ -645,6 +645,10 @@ const PaginatedIconGrid = new Lang.Class({
         return this._nPages;
     },
 
+    getPageHeight: function() {
+        return this._availableHeightPerPageForItems();
+    },
+
     getPageY: function(pageNumber) {
         if (!this._nPages)
             return 0;